package com.yeyuanqi.dao;

import com.yeyuanqi.model.domain.Article;
import com.yeyuanqi.vo.CountVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {

    //根据id查询文章信息
    @Select("SELECT * FROM t_article WHERE id=#{id}")
    public Article selectArticleWithId(Integer id);

    //发表文章，根据@Options获取自动生成的id
    @Insert("INSERT INTO t_article(title,content,created,modified,categories,tags,allow_comment,thumbnail)" +
            "values (#{title},#{content},#{created},#{modified},#{categories},#{tags},#{allowComment},#{thumbnail})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public Integer publishArticle(Article article);

    //文章分页查询
    @Select("SELECT * FROM t_article ORDER BY id DESC")
    public List<Article> selectArticleWithPage();

    //根据id删除文章
    @Delete(" DELETE FROM t_article WHERE id=#{id}")
    public void deleteArticleWithId(int id);

    //根据id更新文章
    public Integer updateArticleWithId(Article article);

    //根据站点服务统计，统计文章数量
    @Select("SELECT COUNT(1) FROM t_article")
    public Integer countAritcle();

    //根据id删除标签
    @Update("UPDATE t_article SET tags =' ' WHERE id=#{id}")
    public void deleteTagsWithId(int id);

    //查询所有文章
    @Select("SELECT * FROM t_article ORDER BY id DESC")
    public List<Article> selectArticleAll();
}
